package charts;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.util.List;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.DefaultXYDataset;
import org.jfree.data.xy.XYDataset;

import vo.Point;
import Utils.ChartUtils;
import application.ChartProperty;

public class ScatterChart {
	public static XYDataset createDataset(List<Point> xydatalist) {
		DefaultXYDataset xydataset = new DefaultXYDataset();
		int size = xydatalist.size();
		System.out.println(size);
		double[][] datas = new double[2][size];
		for (int i = 0; i < size; i++) {
			Point point = xydatalist.get(i);
			double sys = point.getX();
			double dia = point.getY();

			datas[0][i] = sys;
			datas[1][i] = dia;
		}
		xydataset.addSeries("something", datas);
		return xydataset;

	}

	public static void createChart(List<Point> points, String path, ChartProperty cp) {
		JFreeChart jfreechart = ChartFactory.createScatterPlot(cp.getTitle(), cp.getxLabel(), cp.getyLabel(), createDataset(points), PlotOrientation.VERTICAL, true, false, false);
		jfreechart.setBackgroundPaint(Color.white);

		jfreechart.setBorderPaint(Color.GREEN);
		jfreechart.setBorderStroke(new BasicStroke(4f));
		XYPlot xyplot = (XYPlot) jfreechart.getPlot();
		// xyplot.setNoDataMessage(nobloodData);
		// xyplot.setNoDataMessageFont(new Font("", Font.BOLD, 24));
		// xyplot.setNoDataMessagePaint(new Color(87, 149, 117));

		xyplot.setBackgroundPaint(Color.white);
		// ValueAxis vaaxis = xyplot.getDomainAxis();
		// vaaxis.setAxisLineStroke(new BasicStroke(1.5f));

		// ValueAxis va = xyplot.getDomainAxis(0);
		// va.setAxisLineStroke(new BasicStroke(1.5f));
		// va.setAxisLineStroke(new BasicStroke(1.5f)); // 坐标轴粗细
		// va.setAxisLinePaint(new Color(215, 215, 215)); // 坐标轴颜色
		// xyplot.setOutlineStroke(new BasicStroke(1.5f)); // 边框粗细
		// va.setLabelPaint(new Color(10, 10, 10)); // 坐标轴标题颜色
		// va.setTickLabelPaint(new Color(102, 102, 102)); // 坐标轴标尺值颜色
		// ValueAxis axis = xyplot.getRangeAxis();
		// axis.setAxisLineStroke(new BasicStroke(1.5f));

		ChartUtils.saveChart(jfreechart, path);

		System.out.println("draw chart finish");

	}

	public static void main(String args[]) {
		// ArrayList<Point> points =
		// GraphModel.getUserPropVSUserPropModel("followers_count",
		// "friends_count");
		// ScatterChart.createChart(points, "charts/followerVSFriend.jpg");
	}

}
